home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 December / MACPOWER-1997-12.ISO.7z / MACPOWER-1997-12.ISO / AMUG / PROGRAMMING / Raven 1.2.sit / Raven 1.2 / Source / Foundation / OS / ZEvent.h < prev    next >
Text File  |  1997-06-17  |  4KB  |  153 lines

  1. /*
  2.  *  File:       ZEvent.h
  3.  *  Summary:       Classes that encapsulate an EventRecord.
  4.  *  Written by: Jesse Jones
  5.  *
  6.  *  Copyright ゥ 1996 Jesse Jones. 
  7.  *    For conditions of distribution and use, see copyright notice in ZTypes.h  
  8.  *
  9.  *  Change History (most recent first):    
  10.  *
  11.  *         <->     8/01/96    JDJ        Created
  12.  */
  13.  
  14. #pragma once
  15.  
  16. #include <Events.h>
  17.  
  18. #include <ZGeometry.h>
  19. #include <ZTypes.h>
  20.  
  21.  
  22. // ===================================================================================
  23. //    class TEvent
  24. // ===================================================================================
  25. class TEvent {
  26.  
  27. //-----------------------------------
  28. //    Initialization/Destruction
  29. //
  30. public:
  31.     virtual                ~TEvent();
  32.     
  33.                         TEvent();
  34.  
  35.                         TEvent(const EventRecord& event);
  36.  
  37. //-----------------------------------
  38. //    API
  39. //
  40. public:
  41.             EventRecord    GetEventRecord() const                {return mEventRecord;}
  42.  
  43.             MilliSecond    GetTimeStamp() const                {return mTimeStamp;}
  44.                         // Returns the time at which the event occured.
  45.  
  46.  
  47.             TPoint         GetGlobalPosition() const            {return mGlobalPos;}
  48.  
  49.             TPoint         GetPosition() const                    {return mEventRecord.where;}
  50.  
  51.             void         SetPosition(const TPoint& pos)        {mEventRecord.where = pos;}
  52.             
  53.  
  54.             ushort         GetModifiers() const                {return mEventRecord.modifiers;}
  55.  
  56.             void         SetModifiers(ushort modifiers)        {mEventRecord.modifiers = modifiers;}
  57.             
  58.  
  59.             bool         WasCommandKeyDown() const            {return (mEventRecord.modifiers & cmdKey) != 0;}
  60.  
  61.             bool         WasShiftKeyDown() const                {return (mEventRecord.modifiers & shiftKey) != 0;}
  62.  
  63.             bool         WasCapsLockDown() const                {return (mEventRecord.modifiers & alphaLock) != 0;}
  64.  
  65.             bool         WasOptionKeyDown()    const            {return (mEventRecord.modifiers & optionKey) != 0;}
  66.  
  67.             bool         WasControlKeyDown() const            {return (mEventRecord.modifiers & controlKey) != 0;}
  68.  
  69. //-----------------------------------
  70. //    Member data
  71. //
  72. protected:
  73.     EventRecord        mEventRecord;    
  74.     TPoint            mGlobalPos;
  75.     MilliSecond        mTimeStamp;    
  76. };
  77.  
  78.  
  79. // ========================================================================================
  80. //    class TMouseEvent
  81. //        Encapsulates a mouse down, mouse up, or mouse move event.
  82. // ========================================================================================
  83. class TMouseEvent : public TEvent {
  84.  
  85. //-----------------------------------
  86. //    Initialization/Destruction
  87. //
  88. public:
  89.     virtual                ~TMouseEvent();
  90.  
  91.                         TMouseEvent();
  92.  
  93.                         TMouseEvent(const EventRecord& event, long clickCount = 1);
  94.                         // Event.where should be in global coordinates.
  95.  
  96. //-----------------------------------
  97. //    New API
  98. //
  99. public:
  100.             long        GetClickCount() const                {return mClickCount;}
  101.  
  102.             void        SetClickCount(long count)            {ASSERT(count >= 1); mClickCount = count;}
  103.  
  104.             bool         WasMouseDown() const                {return mEventRecord.what == mouseDown;}
  105.  
  106.             bool         WasMouseUp() const                    {return mEventRecord.what == mouseUp;}
  107.  
  108.             bool         WasMouseMoved() const                {return mEventRecord.what == osEvt;}
  109.  
  110. //-----------------------------------
  111. //    Data members
  112. //
  113. protected:
  114.     long    mClickCount;
  115. };
  116.  
  117.  
  118. // ========================================================================================
  119. //    class TKeyEvent
  120. //        Encapsulates a key down, key up, or auto key event.
  121. // ========================================================================================
  122. class TKeyEvent : public TEvent {
  123.  
  124. //-----------------------------------
  125. //    Initialization/Destruction
  126. //
  127. public:
  128.     virtual                ~TKeyEvent();
  129.  
  130.                         TKeyEvent();
  131.  
  132.                         TKeyEvent(const EventRecord& event);
  133.  
  134. //-----------------------------------
  135. //    New API
  136. //
  137. public:
  138.             char         GetChar() const                    {return (char) (mEventRecord.message & charCodeMask);}
  139.  
  140.             int            GetKey() const                    {return (int) ((mEventRecord.message & keyCodeMask) >> 8);}
  141.  
  142.             bool         WasKeyDown() const                {return mEventRecord.what == keyDown || mEventRecord.what == autoKey;}
  143.  
  144.             bool         WasKeyUp() const                {return mEventRecord.what == keyUp;}
  145.  
  146.             bool         WasRepeating() const            {return mEventRecord.what == autoKey;}
  147.  
  148.     static    MilliSecond    GetRepeatFreq();
  149. };
  150.  
  151.  
  152.  
  153.